package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.bean.CompanyGls;
import com.bw.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class OrderController {
    @Resource
    OrderService service;

    @RequestMapping("/listGls")
    public JSONObject listGls(){
        List<CompanyGls> companyGls=service.listGls();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject jsonObject1 = new JSONObject();
        JSONArray objects = new JSONArray();
        for (CompanyGls companyGl : companyGls) {
            objects.add(companyGl.getName());
        }
        jsonObject1.put("categories",objects);
        JSONArray objects1 = new JSONArray();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","公司");
        JSONArray objects2 = new JSONArray();
        for (CompanyGls companyGl : companyGls) {
            objects2.add(companyGl.getTotal());
        }
        jsonObject2.put("data",objects2);
        objects1.add(jsonObject2);
        jsonObject1.put("series",objects1);
        jsonObject.put("data",jsonObject1);
        return jsonObject;
    }
}
